<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class User_Profile_model extends MY_Model
{
	public $_prefix;
	public $_table = 'user_profile';

	public function __construct()
	{
		parent::__construct();

		$this->_prefix = $this->config->item('table_prefix');
		$this->_table = $this->_prefix.$this->config->item('user_profile_table');
	}

	public function find($condition = '', $order_by = '', $limit = 1, $offset = 0)
	{
		if($condition)
		{
			$this->db->where($condition);
		}

		if($order_by)
		{
			$this->db->order_by($order_by);
		}

		$result = $this->db->get($this->_table, $limit, $offset);

		return $result;
	}

	function create_profile($user_id)
	{
		$this->db->set('user_id', $user_id);
		return $this->db->insert($this->_table);
	}

	function get_profile_field($user_id, $fields)
	{
		$this->db->select($fields);
		$this->db->where('user_id', $user_id);
		return $this->db->get($this->_table);
	}

	function get_profile($user_id)
	{
		$this->db->where('user_id', $user_id);
		return $this->db->get($this->_table);
	}

	function set_profile($user_id, $data)
	{
		$this->db->where('user_id', $user_id);
		return $this->db->update($this->_table, $data);
	}

	function delete_profile($user_id)
	{
		$this->db->where('user_id', $user_id);
		return $this->db->delete($this->_table);
	}
}